package com.lin.carbon.validator;

import com.lin.carbon.entity.SysDict;
import com.lin.carbon.mapper.SysDictMapper;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.beans.factory.annotation.Autowired;
public class UniqueDictCodeValidator implements ConstraintValidator<UniqueDictCode, String> {

    @Autowired
    private SysDictMapper sysDictMapper;

    @Override
    public boolean isValid(String dictCode, ConstraintValidatorContext context) {
        if (dictCode == null) {
            return true;
        }
        return sysDictMapper.selectCount(
                new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SysDict>()
                        .eq(SysDict::getDictCode, dictCode)
        ) == 0;
    }
}
